package com.arrogames.tmx {
	import flash.geom.Point;
	
	import org.flexunit.asserts.assertEquals;

	public class CoordinateUtilTest {		
		
		[Test]
		public function reverseTest():void {
			var tileWidth:int = 64;
			var tileHeight:int = 32;
			
			var initialscreen:Point = new Point(100, 150);
			var isoPoint1:Point = CoordinateUtil.screenToIsometric(initialscreen.x, initialscreen.y, tileWidth, tileHeight);
			var screenPoint1:Point =  CoordinateUtil.isometricToScreen(isoPoint1.x, isoPoint1.y, tileWidth, tileHeight);
			
			assertEquals("When changing X coordinate from screen to iso and back to screen, initial screen coordinates are expected", initialscreen.x, screenPoint1.x);
			assertEquals("When changing Y coordinate from screen to iso and back to screen, initial screen coordinates are expected", initialscreen.y, screenPoint1.y);
			
			var initialIso:Point = new Point(6, 3);
			var screenPoint2:Point = CoordinateUtil.isometricToScreen(initialIso.x, initialIso.y, tileWidth, tileHeight);
			var isoPoint2:Point =  CoordinateUtil.screenToIsometric(screenPoint2.x, screenPoint2.y, tileWidth, tileHeight);
			
			assertEquals("When changing X coordinate from iso to screen and back to iso, initial iso coordinates are expected", initialIso.x, isoPoint2.x);
			assertEquals("When changing Y coordinate from iso to screen and back to iso, initial iso coordinates are expected", initialIso.y, isoPoint2.y);
		}
		
		[Test]
		public function screenToIsometricTest():void {
			var tileWidth:int = 128;
			var tileHeight:int = 64;
			
			//64.0, 128.0 --> 2.5,1.5
			var iso:Point = CoordinateUtil.screenToIsometric(64, 128, tileWidth, tileHeight);
			assertEquals("screen.x is expected 2.5", 2.5, iso.x);
			assertEquals("screen.y is expected 1.5", 1.5, iso.y);
			
			//64,96 --> 2,1
			iso = CoordinateUtil.screenToIsometric(64, 96, tileWidth, tileHeight);
			assertEquals("iso.x is expected 2", 2, iso.x);
			assertEquals("iso.y is expected 1", 1, iso.y);
		}
		
		[Test]
		public function isometricToScreenTest():void {
			var tileWidth:int = 128;
			var tileHeight:int = 64;
			
			//2.5,1.5 --> 64.0, 128.0
			var screen:Point = CoordinateUtil.isometricToScreen(2.5, 1.5, tileWidth, tileHeight);
			assertEquals("screen.x is expected 64", 64, screen.x);
			assertEquals("screen.y is expected 128", 128, screen.y);
			
			//2,1 --> 64,96
			screen = CoordinateUtil.isometricToScreen(2, 1, tileWidth, tileHeight);
			assertEquals("screen.x is expected 64", 64, screen.x);
			assertEquals("screen.y is expected 96", 96, screen.y);
		}
		
	}
}